﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QuizSilverlight.Web;
using System.Windows.Ria;


namespace QuizSilverlight
{
    public partial class QuizForm : UserControl
    {
        QuizContext _context;
        LoadOperation _questionOperation;
        LoadOperation _answersOperation;

        public QuizForm()
        {
            
            InitializeComponent();

          
            
        }

        void _questionOperation_Completed(object sender, EventArgs e)
        {
            tbQuestion.DataContext = _questionOperation.AllEntities.Cast<Question>().FirstOrDefault();
            _answersOperation = _context.Load(_context.GetAnswerQuery());
            _answersOperation.Completed += new EventHandler(_answersOperation_Completed);

        }

        void _answersOperation_Completed(object sender, EventArgs e)
        {
           lbAnswers.ItemsSource= _answersOperation.AllEntities.Cast<Answer>();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            _context = new QuizContext();
            _questionOperation = _context.Load(_context.GetQuestionQuery());
            _questionOperation.Completed += new EventHandler(_questionOperation_Completed);
        }



    }
}
